package com.hckjsec.common.skp;
import java.io.UnsupportedEncodingException;

import cn.hutool.core.codec.Base64;
import cn.hutool.core.util.HexUtil;
import cn.hutool.crypto.symmetric.AES;
import cn.hutool.crypto.symmetric.DES;
import cn.hutool.crypto.symmetric.DESede;

/*
 * AES对称加密和解密
 */
public class HCAESUtil {
    /*
     * 加密 1.构造密钥生成器 2.根据ecnodeRules规则初始化密钥生成器 3.产生密钥 4.创建和初始化密码器 5.内容加密 6.返回字符串
     */
    public static String encrypt(String content, String encodeRules) {
        AES encode = new AES(encodeRules.getBytes());
        return encode.encryptBase64(content);
    }

    /*
     * 解密 解密过程： 1.同加密1-4步 2.将加密后的字符串反纺成byte[]数组 3.将加密内容解密
     */
    public static String decrypt(String content, String encodeRules) {
        AES decode = new AES(encodeRules.getBytes());
        return decode.decryptStrFromBase64(content);
    }

    public static void main(String[] args) throws UnsupportedEncodingException {
        String src = "Y9ECeoPqIZZkOp9lo8JgFQnEPcn3fWfehKYGnDtpzK6JM0f4ZQW+qhJh9RJLPig33KiINQ6K1lSMTMXceqW5QVlpr6SYYAXHafwXIQh+J52M5YtXJkjWmDkbqaxHGdplSLKap0PudsfbNosaSEXztiAH8mzwen7j4Mc4YeV2Q7AfhZxK9hTvx7n9\\/Q0ruMrzSuUGkKYzswgdW2AOk5Cbn2m0SypjbzOODlSC5KcCgIrO0GbDTBcrjqomDWkd7yhAE9jq8fFqRF8fnsglZWr8g8CA\\/yXg4cMdkVjxhGmeRb3xglViVObG6cLIOaTKM+mGyG8lJDBVr45gd5+11JNGQ4REgLsOUgTg3Yk3AZ4QKx7O1\\/U1zJULciL1DP52fCP+X4Gg3h9Ky6W7Iqm+yNodpaN5jZYvL2jNErHCo652YfcnV3O1dbI0vqa+exZw5gXn2vkBB6gePOsVLUOZ0riTnfR4aTGbmoUnxgu\\/zg32OP1uR7ZdbzqQXMo2wmnQlaE3AYtjCzIObOqQ12TJ8C6GX\\/4mCFpwWPtOXMQzXEQxO6M\\/PLhh1zpC8p\\/GJ2NtlUTJg4Bnjddn02a8zyGMbsR5fD9s2uc6c1KvEHQECtJ\\/1KxzyVh7sUpj9L+dMmVmOddNxNk5wAmmmHYezLJyrb2aLTnIkuEfyw4RaVqbcQE7OBpUxbOfuWU2q7mefKgwQxyOzL+aLzo2Fq9iSjtXuf2WhSgr7s5WFF3rExGTNpVdgi0=";
        System.out.println(new String(Base64.decode(src), "UTF-8"));
        // String decode = decrypt(src, "76E89A93334038D6E9E258987AABE9DD");
        // System.out.println(decode);
        // DES desc = new DES(HexUtil.decodeHex("76E89A93334038D6E9E258987AABE9DD"));
        // String d = desc.decryptStrFromBase64(src);
        //
        // System.out.println(d);
    }
}
